package chatRoom.server;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.LinkedList;

import chatRoom.network.Connection;

public class ChatConnection extends Connection 
{
	private LinkedList<String> received;
	private String name;
	private boolean done = false;

	public ChatConnection(Socket socket) 
	{
		setSocket(socket);
		received = new LinkedList<String>();
	}

	public void run() 
	{
		while (! done) 
		{
			try 
			{
				String string = getInput().readLine();
				if (string != null)
				{
					System.out.println(string);
					received.add(string);
				}
			}
			catch (IOException e) 
			{
				System.out.println("User Disconnected");
				done = true;
			} 
		}
	}

	public LinkedList<String> getReceived() 
	{
		LinkedList<String> temp = received;
		received = new LinkedList<String>();
		return temp;
	}

	public void sendToClient(String command) 
	{
		getOutput().println(command);
	}
	
	public boolean isTerminated()
	{
		return done;
	}
}
